<?php foreach ($matPremsSelected as $mps) { ?>
    <tr class="ligneMatPrem">
        <td>
            <select class="idMatPrem">
                <option>Selectionnez une matPrem</option>
                <?php
                foreach ($matPrems as $matPrem) {
                    $selected = '';
                    if ($matPrem->ARTICLE_ID == $mps->MATPREM_ID)
                        $selected = 'selected="selected"';
                    ?>
                    <option value="<?php echo $matPrem->ARTICLE_ID; ?>" <?php echo $selected; ?>><?php echo $matPrem->ARTICLE_REF . ' | ' . $matPrem->ARTICLE_REF; ?></option>
    <?php } ?>
            </select>
        </td>
        <td class="quantite"><input type="number" min="0" class="quantite" placeholder="Quantité" value="<?php echo $mps->NOMENCLATURE_QUANTITE; ?>"/> <span><?php echo $mps->UNITE_CODE; ?></span></td>
    </tr>

<?php } ?>

<tr class="ligneMatPrem">
    <td>
        <select class="idMatPrem">
            <option value="0">Selectionnez une matPrem</option>
            <?php foreach ($matPrems as $matPrem) { ?>
                <option value="<?php echo $matPrem->ARTICLE_ID; ?>"><?php echo $matPrem->ARTICLE_REF . ' | ' . $matPrem->ARTICLE_REF; ?></option>
<?php } ?>
        </select>
    </td>
    <td class="quantite"><input type="number" min="0" class="quantite" placeholder="Quantité"/> <span></span></td>
</tr>



<script>
    $(document).ready(function() {
        $('select.idMatPrem').on('change', function() {
            $.ajax({
                url: site_url+"produit/getMatPremUnit",
                type:'POST',
                data: {
                    idMatPrem : $(this).val()
                },
                success : function(e) {
                    $('select.idMatPrem').parents('tr').children('td.quantite').children('span').html(e);
                }
            });
        });
    });
</script>